package JavaSEAdvance.day06_Date.D607_HomeWork;

import java.time.LocalDate;
import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/22
 */
public class Test03 {
    /**
     * 3. 键盘录入一个年份，判断这个年份是平年还是闰年（提示，闰年2月有29天，平年2月只有28天）
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int year = 0;
        while (true) {
            System.out.println("请输入一个年份：");
            String s = sc.nextLine();
            try {
                year = Integer.parseInt(s);
            } catch (NumberFormatException e) {
                System.out.println("您输入的年数有误，请输入一个整数年份。");
                continue;
            }
            break;
        }
        LocalDate date = LocalDate.of(year, 3, 1);
        LocalDate date1 = date.minusDays(1L);
        if (date1.getDayOfMonth() == 29) {
            System.out.println(year + "年是闰年。");
        } else {
            System.out.println(year + "年是平年。");
        }
    }
}
